<?php
/**
 * @version		0.2.0 joomla zmluvy $
 * @package		com_zjmluvy
 * @copyright	Copyright © 2011 - All rights reserved.
 * @license		GNU/GPL
 * @author    AdrianKo		
 * @website   http://code.google.com/p/joomla-zmluvy
 *
 *
 *1.3.2012
 */

// no direct access
defined('_JEXEC') or die('Restricted access');
JHTML::_('behavior.tooltip');  ?>

<?php

	JToolBarHelper::title( JText::_( '&nbsp;&nbsp;&nbsp;'.JText::_( 'title_JZMLUVY' ) ), 'controlpanel' );
    
  //*** nastavenie s subore config.xml
  JToolBarHelper::preferences('com_jzmluvy', '500');
  // JToolBarHelper::help( 'changelog',true );
  $params	= &JComponentHelper::getParams('com_jzmluvy');
  $folder  = JPATH_ADMINISTRATOR .DS. 'components'.DS.'com_jzmluvy';
  $path =  JURI::root().'administrator/components/com_jzmluvy/assets/images/controlpanel/';
  // $path =  JURI::root().'administrator'.DS.'components'.DS.'com_jzmluvy'.DS.'assets'.DS.'images'.DS.'controlpanel'.DS;
  $version = jZmluvyHelper::getVersion();
  
  //*** preformatovanie datumu vytvorenia komponenty
  $date = new DateTime($version['creationdate']);
  $datum = $date->format('j.n.Y');

    // aktualna verzia
    if (isset($version['version']) && $version['version'] != '') {
			$akt_verz = $version['version'];
		} else {
			$akt_verz = "9.9.9";
		}
// kontrola verzie  
function check_ver()
  {
    //*** vyhladanie info o novej verzii;
    $handle = @fopen("http://www.vpm.sk/jzmluva.ver", "rb");
    // ak subor alebo cesta neexistuje
    if($handle)
    {
    return stream_get_contents($handle);
    fclose($handle);
    }
      else
    {

    return "error";
    }
  }
$new_verz = check_ver();

/*
      // informacia o zlom zisteni verzie
      if($this->params->get( 'nova_verzia' ))
      {    
        $error = JText::_( 'INFO_VERZIA_ERROR'); 
        JError::raiseNotice('SOME_ERROR_CODE', $error );
      } 
*/

// echo "nova: ".$new_verz."  aktualna: ".$akt_verz." rozdiel:".strnatcmp($akt_verz,$new_verz);                 

?>     
<form action="index.php?option=com_jzmluvy" method="post" name="adminForm">
  <div class="col width-60">
    <fieldset class="adminform">
      <legend>
        <?php echo JText::_( 'cp_CONTROLPANEL' ); ?>
      </legend>
      <div id="cpanel" >
        <div style="float:left;">
          <div class="icon"> 
             <a href="index.php?option=com_jzmluvy&amp;view=zmluva">  
              <img src="<?php echo $path ?>cp_zmluvy.png" alt="<?php echo JText::_( 'cp_ZMLUVY' ); ?>"  /> 
              <span>
                  <?php echo JText::_( 'cp_ZMLUVY' ); ?>
              </span></a>
          </div>
        </div>
        <div style="float:left;">
          <div class="icon"> 
            <a href="index.php?option=com_jzmluvy&amp;view=faktura"> 
              <img src="<?php echo $path ?>cp_faktury.png" alt="<?php echo JText::_( 'cp_FAKTURY' ); ?>"  /> 
              <span>
                <?php echo JText::_( 'cp_FAKTURY' ); ?>
              </span></a>
          </div>
        </div>
        <div style="float:left;">
          <div class="icon"> 
            <a href="index.php?option=com_jzmluvy&amp;view=objednavka"> 
              <img src="<?php echo $path ?>cp_objednavky.png" alt="<?php echo JText::_( 'cp_OBJEDNAVKY' ); ?>"  /> 
              <span>
                <?php echo JText::_( 'cp_OBJEDNAVKY' ); ?>
              </span></a>
          </div>
        </div>
        <div style="float:left;">
          <div class="icon">
            <a href="index.php?option=com_jzmluvy&amp;view=partner"> 
              <img src="<?php echo $path ?>cp_partneri.png" alt="<?php echo JText::_( 'cp_PARTNERI' ); ?>"  /> 
              <span>
                <?php echo JText::_( 'cp_PARTNERI' ); ?>
              </span></a>
          </div>
        </div>
        
        <?php if (jZmluvyHelper::pristup()) : ?>        
        <div style="float:left;">
          <div class="icon">
            <a href="index.php?option=com_jzmluvy&amp;view=nastaveni"> 
              <img src="<?php echo $path ?>cp_settings.png" alt="<?php echo JText::_( 'cp_NASTAVENIE' ); ?>"  /> 
              <span>
                <?php echo JText::_( 'cp_NASTAVENIE' ); ?>
              </span></a>
          </div>
        </div>        
        <?php endif ?>
      </div>
    </fieldset>
  </div>
  <div style="float:right;" class="col width-40">
    <fieldset class="adminform">
      <table class="admintable">
        <tr> 
          <td colspan="2">
            <label for="title"> 
              <img alt="jZmluvy" width="130" src="<?php echo $path ?>cp_logo.png" />
            </label></td>
        </tr>
        <tr> 
          <td class="key"> 
            <label for="title" width="100">
              <?php echo JText::_( 'cp_BLOK_VERZIA' ); ?>
            </label>      </td> 
          <td >
          
      <?php
      // nova verzia
      if(strnatcmp($akt_verz,$new_verz) == "-1") :
			if($this->params->get( 'nova_verzia' ) && $new_verzia=="error" ) :
      $this->_error = JText::_( 'cp_VER_NOVA' );
      JError::raiseNotice('SOME_ERROR_CODE', $this->_error );
      endif;
      echo $akt_verz  ?> 
      <?php if($new_verzia == "error") : ?>
      <img src="<?php echo $path ?>new.png" alt="<?php echo JText::_( 'cp_VER_NOVA' ) ?>" width="16" title="<?php echo JText::_( 'cp_VER_NOVA' ) ?>" />
      <?php endif; ?>
      
      <?php // instalovana vezrzia je vacsia ako vobec existuje ! (alebo zla instalacia)
      elseif(strnatcmp($akt_verz,$new_verz) == "1") :
			if($this->params->get( 'nova_verzia' )) :
      $this->_error = JText::_( 'cp_VER_ZLA' );
      JError::raiseNotice('SOME_ERROR_CODE', $this->_error );
      endif;
      echo $akt_verz  ?> 
      <img src="<?php echo $path ?>error.png" alt="<?php echo JText::_( 'cp_VER_ZLA' ) ?>" title="<?php echo JText::_( 'cp_VER_ZLA' ) ?>" width="16"  />
            
      <?php // posledna dostupna verzia
      elseif(strnatcmp($akt_verz,$new_verz) == "0") :
      echo $akt_verz ?>
      <img src="<?php echo $path ?>ok.png" alt="O.K."  title="O.K." width="16"  />
      <?php endif; ?>
            
      </td>
        </tr>
        <?php if((strnatcmp($akt_verz,$new_verz)) == "-1") : ?>
        <tr> 
          <td class="key"> 
            <label for="title" width="100">
              <?php echo JText::_( 'cp_BLOK_DOWNLOAD' ); ?>
            </label>      </td><td>
            <a href="http://code.google.com/p/joomla-zmluvy/downloads" target="_blank"> 
              <span>
                <?php echo JText::_( 'cp_VER_DOWNLOAD' ); ?>&nbsp;
                <?php echo $new_verz?>&nbsp;<img src="<?php echo $path ?>download.png" title="Download" alt="Download"  />
              </span></a>
            </td>
        </tr>
        <?php endif ?>
        <?php if((strnatcmp($akt_verz,$new_verz)) == "1") : ?>
        <tr> 
          <td class="key"> 
            <label for="title" width="100">
              <?php echo JText::_( 'cp_BLOK_DOWNLOAD_AKT' ); ?>
            </label>      </td><td>
            <a href="http://code.google.com/p/joomla-zmluvy/downloads" target="_blank"> 
              <span>
                <?php echo JText::_( 'cp_VER_DOWNLOAD_AKT' ); ?>&nbsp;
                <?php echo $new_verz?>&nbsp;<img src="<?php echo $path ?>download.png" title="Download" alt="Download"  />
              </span></a>
            </td>
        </tr>
        <?php endif ?>
              

        <?php if ($new_verz=="error") : ?>
        <tr>
          <td class="key" title="<?php echo JText::_( 'cp_BLOK_NEZISTENA_I' ); ?>"> 
            <label for="title" width="100">
              <?php echo JText::_( 'cp_BLOK_NEZISTENA' ); ?>
            </label>      </td><td>
            <a href="http://code.google.com/p/joomla-zmluvy/downloads" target="_blank"> 
              <span>
                <?php echo JText::_( 'cp_VER_NEZISTENA' ); ?>&nbsp;
                &nbsp;<img src="<?php echo $path ?>download.png" title="Download" alt="Download"  />
              </span></a>
            </td>
        </tr>

        <?php endif ?>
        
        <tr> 
          <td class="key"> 
            <label for="title" width="100">
              <?php echo JText::_( 'cp_BLOK_DATUM' ); ?>
            </label>      </td><td>
            <?php echo $datum ?></td>
        </tr>
        <tr> 
          <td class="key" valign="top"> 
            <label for="title" width="100">
              <?php echo JText::_( 'cp_BLOK_POPIS' ); ?>
            </label>      </td><td>
            <?php echo JText::_( 'cp_BLOK_POPIS_TEXT' ); ?></td>
        </tr>
        <tr> 
          <td class="key" valign="top"> 
            <label for="title" width="100">
              <?php echo JText::_( 'cp_BLOK_PROJEKT' ); ?>
            </label>      </td><td>
            <?php echo JText::_( 'cp_BLOK_PROJEKT_TEXT' ); ?></td>
        </tr>
         <tr> 
          <td class="key" valign="top"> 
            <label for="title" width="100">
              <?php echo JText::_( 'cp_BLOK_FORUM' ); ?>
            </label>      </td><td>
            <?php echo JText::_( 'cp_BLOK_FORUM_TEXT' ); ?></td>
        </tr>
        <tr> 
          <td class="key" valign="top"> 
            <label for="title" width="100">
              <?php echo JText::_( 'cp_BLOK_VDAKA' ); ?>
            </label>      </td><td>
            <?php echo JText::_( 'cp_BLOK_VDAKA_TEXT' ); ?></td>
        </tr>
              </table>
    </fieldset>
  </div>
  <div class="clr">
  </div>
  <input type="hidden" name="option" value="com_jzmluvy" /> 
  <input type="hidden" name="view" value="jzmluvy" /> 
  <input type="hidden" name="controller" value="" /> 
  <input type="hidden" name="boxchecked" value="0" /> 
  <input type="hidden" name="task" value="" /> 
  <input type="hidden" name="redirect" value="<?php //echo $redirect; ?>" /> 
  <?php echo JHTML::_( 'form.token' ); ?>
</form>
